package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationApprovalVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.manager.LindiSubsidyApplicationManager;
import com.minimalist.lindi.service.LindiSubsidyApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标交易平台_补贴申请控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_补贴申请管理")
@RequestMapping("/lindi/subsidyApplication")
public class LindiSubsidyApplicationController{

    @Autowired
    private LindiSubsidyApplicationService service;

    @Autowired
    private LindiSubsidyApplicationManager lindiSubsidyApplicationManager;

    @PostMapping("/addSubsidyApplication")
    @Operation(summary = "添加补贴申请")
    public R<?> addSubsidyApplication(
            @RequestBody @Validated(Add.class)
            LindiSubsidyApplicationVO subsidyApplicationVO){
        service.addSubsidyApplication(subsidyApplicationVO);
        return R.ok();
    }

    @DeleteMapping("/deleteSubsidyApplicationBySubsidyApplicationId")
    @Operation(summary = "删除补贴申请 -> 根据补贴申请ID删除")
    public R<?> deleteSubsidyApplicationBySubsidyApplicationId(
            @RequestParam("subsidyApplicationId")
            @NotNull(message = "补贴申请ID不能为空")
            @Parameter(name = "subsidyApplicationId", required = true, description = "补贴申请ID")
            Long subsidyApplicationId){
        service.deleteSubsidyApplicationBySubsidyApplicationId(
                subsidyApplicationId);
        return R.ok();
    }

    @PutMapping("/updateSubsidyApplicationBySubsidyApplicationId")
    @Operation(summary = "修改补贴申请")
    public R<?> updateSubsidyApplicationBySubsidyApplicationId(
            @RequestBody @Validated(Update.class)
            LindiSubsidyApplicationVO subsidyApplicationVO){
        service.updateSubsidyApplicationBySubsidyApplicationId(
                subsidyApplicationVO);
        return R.ok();
    }

    @GetMapping("/getPageSubsidyApplicationList")
    @Operation(summary = "查询补贴申请列表(分页)")
    public R<PageResp<LindiSubsidyApplicationVO>> getPageSubsidyApplicationList(
            @RequestBody LindiSubsidyApplicationQueryVO queryVO){
        return R.ok(service.getPageSubsidyApplicationList(queryVO));
    }

    @GetMapping("/getSubsidyApplicationBySubsidyApplicationId/{subsidyApplicationId}")
    @Operation(summary = "根据补贴申请ID查询补贴申请")
    public R<LindiSubsidyApplicationVO> getSubsidyApplicationBySubsidyApplicationId(
            @PathVariable(value = "subsidyApplicationId")
            @NotNull(message = "补贴申请ID不能为空")
            @Parameter(name = "subsidyApplicationId", description = "补贴申请ID", required = true)
            Long subsidyApplicationId){
        return R.ok(service.getSubsidyApplicationBySubsidyApplicationId(
                subsidyApplicationId));
    }

    @PostMapping("/approveSubsidyApplication")
    @Operation(summary = "审批补贴申请")
    public R<?> approveSubsidyApplication(
            @Validated @RequestBody LindiSubsidyApplicationApprovalVO approvalVO){
        lindiSubsidyApplicationManager.approveSubsidyApplication(approvalVO);
        return R.ok();
    }

    @PostMapping("/deleteSubsidyApplicationFileByFileId")
    @Operation(summary = "删除补贴申请文件 -> 根据文件ID删除")
    public R<?> deleteSubsidyApplicationFileByFileId(
            @RequestParam("fileId")
            @NotNull(message = "文件ID不能为空")
            @Parameter(name = "fileId", description = "文件ID", required = true)
            Long fileId){
        service.deleteSubsidyApplicationFileByFileId(fileId);
        return R.ok();
    }
}